/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package businessLogic;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import persistence.*;

/**
 *
 * @author breinesg
 */
@Stateless
public class DataMgrBean implements DataMgr {
    @PersistenceContext
    private EntityManager em;

    @Override
    public void addClient(Client cl) {
        //throw new UnsupportedOperationException("Not supported yet.");
          
        em.persist(cl);            
        
    }
    
    @Override
    public Client getClientById(int id) {
        //throw new UnsupportedOperationException("Not supported yet.");
           
            Client cl = em.find(Client.class, id);            
            
            return cl;
    }
    
    
    
    

    @Override
    public void addMedia(Medium md) {
        
        em.persist(md);
        //throw new UnsupportedOperationException("Not supported yet.");       
        
        
    }
    public void addBook(String title, String isbn, String author) {
        Library lib = new Library();
        lib.setLastName("ITS");
        lib.setLocation("Urstein");
        em.persist(lib);
        Shelf s = new Shelf();
        s.setLibraryId(lib);
        s.setPosition(1);
        s.setRow(1);
        s.setCol(1);
        em.persist(s);
        SimpleBook book = new SimpleBook();
        book.setTitle(title);
        book.setIsbn(isbn);
        book.setAuthor(author);
        book.setShelfId(s);
        em.persist(book);
    }
    
    
    @Override
     public Shelf getShelfByID(int id){
        
         Shelf shelf = em.find(Shelf.class,id);
         
         return shelf;               
      }
    @Override
    public List<Medium> getAllMedia() {
        return em.createNamedQuery("Medium.findAll", Medium.class).getResultList();
    }
    
  





}
